package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.SetmealService;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Category;
import com.itheima.reggie.domain.Dish;
import com.itheima.reggie.domain.Setmeal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class SetmealController {

    @Autowired
    private SetmealService setmealService;
    //查询套餐管理列表
    @GetMapping("/setmeal/page")
    public ResultInfo findMy(Integer page,Integer pageSize,String name){
       Page<Setmeal>zhu= setmealService.findMy(page,pageSize,name);
        return ResultInfo.success(zhu);
    }


    //回显菜品
    @GetMapping("/dish/list")
    public ResultInfo findMyId(Long categoryId,String name){
       List<Dish>list= setmealService.findMyId(categoryId, name);
        return ResultInfo.success(list);
    }


    //添加菜品套餐
    @PostMapping("/setmeal")
    public ResultInfo save(@RequestBody Setmeal setmeal){
        setmealService.save(setmeal);
        return ResultInfo.success(null);
    }


    //删除菜品套餐
    @DeleteMapping("/setmeal")
    public ResultInfo update(Long ids){
        setmealService.update(ids);
        return ResultInfo.success(null);
    }


      //根据id回显数据
    @GetMapping("/setmeal/{id}")
    public ResultInfo zhu(@PathVariable("id") Long id){
        System.out.println(id);
        Setmeal setmeal  = setmealService.zhu(id);
        return ResultInfo.success(setmeal);
    }


    //修改菜品套餐
    @PutMapping("/setmeal")
    public ResultInfo updated(@RequestBody Setmeal setmeal){
        setmealService.updated(setmeal);
        return ResultInfo.success(null);
    }


    //批量起 停售
    @PostMapping("/setmeal/status/{ids}")
    public ResultInfo ts(@PathVariable("ids") int id, Long[] ids){
        setmealService.ts(id,ids);
        return ResultInfo.success(null);

    }
}
